package org.cmroot.certmaster.server;

import org.cmroot.certmaster.shared.PKIServiceException;
import org.cmroot.certmaster.service.PkiService;
import org.cmroot.certmaster.client.GWTClientService;
import org.cmroot.certmaster.shared.dto.Pkcs10DTO;
import org.cmroot.certmaster.shared.dto.X509DTO;
import org.cmroot.certmaster.shared.dto.ext.Pkcs10ExtDTO;
import org.cmroot.certmaster.shared.dto.ext.X509ExtDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Controller
@RequestMapping("/certmaster/*")
public class CertMasterService extends BaseRemoteService implements GWTClientService {
    
    @Autowired
    @Qualifier("pkiservice")
    private PkiService pkiservice;

    @Override
    public void newRequest(String request) throws PKIServiceException {
        pkiservice.newRequest(request);
    }

    @Override
    public void removePKCS(String clazz, Long id) throws PKIServiceException {
        pkiservice.removePKCS(clazz, id);
    }

    @Override
    public List<Pkcs10DTO> getRequests() throws PKIServiceException {
        return pkiservice.getAllPKCS10();
    }

    @Override
    public List<X509DTO> getTree() throws PKIServiceException {
        return pkiservice.getAllX509();
    }

    @Override
    public List<X509DTO> getX509Children(Long parent_id) throws PKIServiceException {
        return pkiservice.getX509Children(parent_id);
    }

    @Override
    public X509DTO getX509(Long id) throws PKIServiceException {
        return pkiservice.getX509(id);
    }

    @Override
    public X509ExtDTO getExtX509(Long id) throws PKIServiceException {
        return  pkiservice.getExtX509(id);
    }

    @Override
    public Pkcs10ExtDTO getExtPkcs10(Long id) throws PKIServiceException {
        return pkiservice.getExtPkcs10(id);
    }

    @Override
    public List<X509DTO> importChain(String text) throws PKIServiceException {
        return pkiservice.importChain(text);
    }

    @Override
    public List<X509DTO> getCA() throws PKIServiceException {
        return pkiservice.getCA();
    }
}